import type { RouteObject } from "react-router-dom";
import LazyLoadAndPermission from "../util/LazyLoadAndPermission";
import { friendsPage } from "@/router/page/index.ts";
import { getFriendDetil } from "@/api/xhr/friends";
import { getStoreItem } from "@/util/storage";
const friends: RouteObject[] = [
  {
    path: "friends",
    element: LazyLoadAndPermission(
      friendsPage.FriendsList,
      "friends",
      true,
      true
    ),
    children: [
      {
        path: "detail/:friendsId",
        element: LazyLoadAndPermission(
          friendsPage.FriendsDetil,
          "friendsDetil",
          true,
          true
        ),
        loader: async ({ params }) => {
          const userId = JSON.parse(getStoreItem("userinfo"))?.id;
          const friendUserId = Number(params.friendsId);
          if (userId) {
            const data = await getFriendDetil({ userId, friendUserId });
            return data.data;
          }
          return {};
        }
      }
    ]
  }
];

export default friends;
